package com.campus.controller;

import com.campus.pojo.dto.LabEquipmentDTO;
import com.campus.pojo.dto.LabEquipmentPageQueryDTO;
import com.campus.pojo.entity.LabEquipment;
import com.campus.pojo.vo.LabEquipmentVO;
import com.campus.result.PageResult;
import com.campus.result.Result;
import com.campus.service.LabEquipmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/labEquipment")
@Slf4j
public class LabEquipmentController {
    
    @Autowired
    private LabEquipmentService labEquipmentService;
    
    /**
     * 新增实验室设备
     *
     * @param labEquipmentDTO
     * @return
     */
    @PostMapping
    public Result save(@RequestBody LabEquipmentDTO labEquipmentDTO) {
        log.info("新增实验室设备：{}", labEquipmentDTO);
        labEquipmentService.save(labEquipmentDTO);
        return Result.success();
    }
    
    /**
     * 批量删除实验室设备
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Long> ids) {
        log.info("批量删除实验室设备 ids：{}", ids);
        labEquipmentService.deleteByIds(ids);
        return Result.success();
    }
    
    /**
     * 分页查询实验室设备
     * @return
     */
    @GetMapping("/pageQuery")
    public Result<PageResult<LabEquipmentVO>> pageQuery(LabEquipmentPageQueryDTO labEquipmentPageQueryDTO) {
        log.info("实验室设备分页查询：{}", labEquipmentPageQueryDTO);
        PageResult<LabEquipmentVO> pageResult = labEquipmentService.pageQuery(labEquipmentPageQueryDTO);
        return Result.success(pageResult);
    }
    
    /**
     * 预约实验室设备-修改状态
     */
    @PutMapping("/book/{id}/{status}")
    public Result book(@PathVariable Long id, @PathVariable Integer status) {
        log.info("预约实验室设备id: {}  修改状态为：{}", id, status);
        labEquipmentService.updateStatus(id, status);
        return Result.success();
    }
    
    /**
     * 查询回显
     */
    @GetMapping("/{id}")
    public Result<LabEquipment> getById(@PathVariable Long id) {
        log.info("查询回显 id: {}", id);
        LabEquipment labEquipment = labEquipmentService.getById(id);
        return Result.success(labEquipment);
    }
    
    /**
     * 修改实验室设备信息
     */
    @PutMapping
    public Result update(@RequestBody LabEquipmentDTO labEquipmentDTO) {
        log.info("修改实验室设备信息：{}", labEquipmentDTO);
        labEquipmentService.update(labEquipmentDTO);
        return Result.success();
    }
}
